using SheLife.Domain.Entities;

namespace SheLife.Application.Interfaces
{
    /// <summary>
    /// 系统配置服务接口
    /// </summary>
    public interface ISystemConfigService
    {
        Task<SystemConfig?> GetSystemConfigByIdAsync(Guid id);
        Task<SystemConfig?> GetSystemConfigByKeyAsync(string key);
        Task<IEnumerable<SystemConfig>> GetAllSystemConfigsAsync();
        Task<SystemConfig> CreateSystemConfigAsync(string key, string value, string? description = null, string? category = null);
        Task<SystemConfig?> UpdateSystemConfigAsync(Guid id, string? value, string? description, string? category);
        Task<bool> DeleteSystemConfigAsync(Guid id);
        Task<Dictionary<string, string>> GetSystemConfigsByCategoryAsync(string category);
    }

    /// <summary>
    /// 系统日志服务接口
    /// </summary>
    public interface ISystemLogService
    {
        Task<SystemLog?> GetSystemLogByIdAsync(Guid id);
        Task<IEnumerable<SystemLog>> GetSystemLogsByLevelAsync(string level, int page = 1, int pageSize = 20);
        Task<IEnumerable<SystemLog>> GetSystemLogsByCategoryAsync(string category, int page = 1, int pageSize = 20);
        Task<IEnumerable<SystemLog>> GetSystemLogsByUserIdAsync(Guid userId, int page = 1, int pageSize = 20);
        Task<IEnumerable<SystemLog>> GetSystemLogsByDateRangeAsync(DateTime startDate, DateTime endDate, int page = 1, int pageSize = 20);
        Task<SystemLog> CreateSystemLogAsync(string level, string category, string message, Guid? userId = null, string? details = null);
        Task<bool> DeleteSystemLogAsync(Guid id);
        Task<bool> DeleteSystemLogsByDateRangeAsync(DateTime startDate, DateTime endDate);
        Task<Dictionary<string, object>> GetSystemLogStatisticsAsync(int days = 30);
    }

    /// <summary>
    /// 系统通知服务接口
    /// </summary>
    public interface ISystemNotificationService
    {
        Task<SystemNotification?> GetSystemNotificationByIdAsync(Guid id);
        Task<IEnumerable<SystemNotification>> GetSystemNotificationsByUserIdAsync(Guid userId, int page = 1, int pageSize = 20);
        Task<IEnumerable<SystemNotification>> GetUnreadSystemNotificationsByUserIdAsync(Guid userId, int page = 1, int pageSize = 20);
        Task<IEnumerable<SystemNotification>> GetSystemNotificationsByTypeAsync(string type, int page = 1, int pageSize = 20);
        Task<SystemNotification> CreateSystemNotificationAsync(Guid userId, string type, string title, string content, string? actionUrl = null);
        Task<SystemNotification?> UpdateSystemNotificationAsync(Guid id, string? title, string? content, string? actionUrl);
        Task<bool> DeleteSystemNotificationAsync(Guid id);
        Task<bool> MarkSystemNotificationAsReadAsync(Guid id);
        Task<bool> MarkAllSystemNotificationsAsReadAsync(Guid userId);
        Task<int> GetUnreadSystemNotificationCountAsync(Guid userId);
    }

    /// <summary>
    /// 系统任务服务接口
    /// </summary>
    public interface ISystemTaskService
    {
        Task<SystemTask?> GetSystemTaskByIdAsync(Guid id);
        Task<IEnumerable<SystemTask>> GetAllSystemTasksAsync(int page = 1, int pageSize = 20);
        Task<IEnumerable<SystemTask>> GetPendingSystemTasksAsync(int page = 1, int pageSize = 20);
        Task<IEnumerable<SystemTask>> GetRunningSystemTasksAsync(int page = 1, int pageSize = 20);
        Task<IEnumerable<SystemTask>> GetCompletedSystemTasksAsync(int page = 1, int pageSize = 20);
        Task<IEnumerable<SystemTask>> GetFailedSystemTasksAsync(int page = 1, int pageSize = 20);
        Task<SystemTask> CreateSystemTaskAsync(string name, string type, string? parameters = null, DateTime? scheduledAt = null);
        Task<SystemTask?> UpdateSystemTaskAsync(Guid id, string? name, string? type, string? parameters, DateTime? scheduledAt);
        Task<bool> DeleteSystemTaskAsync(Guid id);
        Task<SystemTask?> StartSystemTaskAsync(Guid id);
        Task<SystemTask?> CompleteSystemTaskAsync(Guid id, string? result = null);
        Task<SystemTask?> FailSystemTaskAsync(Guid id, string error);
        Task<SystemTask?> CancelSystemTaskAsync(Guid id);
        Task<Dictionary<string, object>> GetSystemTaskStatisticsAsync();
    }

    /// <summary>
    /// 系统版本服务接口
    /// </summary>
    public interface ISystemVersionService
    {
        Task<SystemVersion?> GetSystemVersionByIdAsync(Guid id);
        Task<SystemVersion?> GetLatestSystemVersionAsync();
        Task<IEnumerable<SystemVersion>> GetAllSystemVersionsAsync();
        Task<SystemVersion> CreateSystemVersionAsync(string version, string description, string? downloadUrl = null, bool isForced = false);
        Task<SystemVersion?> UpdateSystemVersionAsync(Guid id, string? description, string? downloadUrl, bool? isForced);
        Task<bool> DeleteSystemVersionAsync(Guid id);
        Task<SystemVersion?> PublishSystemVersionAsync(Guid id);
        Task<SystemVersion?> UnpublishSystemVersionAsync(Guid id);
        Task<bool> IsNewerSystemVersionAvailableAsync(string currentVersion);
    }

    /// <summary>
    /// 系统备份服务接口
    /// </summary>
    public interface ISystemBackupService
    {
        Task<SystemBackup?> GetSystemBackupByIdAsync(Guid id);
        Task<IEnumerable<SystemBackup>> GetAllSystemBackupsAsync();
        Task<SystemBackup> CreateSystemBackupAsync(string type, string? description = null);
        Task<bool> DeleteSystemBackupAsync(Guid id);
        Task<SystemBackup?> RestoreSystemBackupAsync(Guid id);
        Task<SystemBackup?> StartSystemBackupAsync(Guid id);
        Task<SystemBackup?> CompleteSystemBackupAsync(Guid id, string? filePath = null);
        Task<SystemBackup?> FailSystemBackupAsync(Guid id, string error);
        Task<bool> DeleteExpiredSystemBackupsAsync(int daysToKeep = 30);
        Task<Dictionary<string, object>> GetSystemBackupStatisticsAsync();
    }

    /// <summary>
    /// 系统缓存服务接口
    /// </summary>
    public interface ISystemCacheService
    {
        Task<SystemCache?> GetSystemCacheByIdAsync(Guid id);
        Task<SystemCache?> GetSystemCacheByKeyAsync(string key);
        Task<IEnumerable<SystemCache>> GetAllSystemCachesAsync();
        Task<SystemCache> CreateSystemCacheAsync(string key, string value, int? expirationMinutes = null);
        Task<SystemCache?> UpdateSystemCacheAsync(Guid id, string value, int? expirationMinutes = null);
        Task<bool> DeleteSystemCacheAsync(Guid id);
        Task<bool> DeleteSystemCacheByKeyAsync(string key);
        Task<bool> DeleteExpiredSystemCachesAsync();
        Task<T?> GetSystemCacheValueAsync<T>(string key) where T : class;
        Task<bool> SetSystemCacheValueAsync<T>(string key, T value, int? expirationMinutes = null) where T : class;
        Task<bool> RemoveSystemCacheValueAsync(string key);
        Task<bool> ClearAllSystemCacheAsync();
        Task<Dictionary<string, object>> GetSystemCacheStatisticsAsync();
    }

    /// <summary>
    /// 系统权限服务接口
    /// </summary>
    public interface ISystemPermissionService
    {
        Task<SystemPermission?> GetSystemPermissionByIdAsync(Guid id);
        Task<SystemPermission?> GetSystemPermissionByNameAsync(string name);
        Task<IEnumerable<SystemPermission>> GetAllSystemPermissionsAsync();
        Task<SystemPermission> CreateSystemPermissionAsync(string name, string description, string? category = null);
        Task<SystemPermission?> UpdateSystemPermissionAsync(Guid id, string? description, string? category);
        Task<bool> DeleteSystemPermissionAsync(Guid id);
        Task<IEnumerable<SystemPermission>> GetSystemPermissionsByCategoryAsync(string category);
        Task<bool> CheckUserHasPermissionAsync(Guid userId, string permissionName);
        Task<IEnumerable<SystemPermission>> GetUserPermissionsAsync(Guid userId);
        Task<bool> GrantPermissionToUserAsync(Guid userId, Guid permissionId);
        Task<bool> RevokePermissionFromUserAsync(Guid userId, Guid permissionId);
    }

    /// <summary>
    /// 系统角色服务接口
    /// </summary>
    public interface ISystemRoleService
    {
        Task<SystemRole?> GetSystemRoleByIdAsync(Guid id);
        Task<SystemRole?> GetSystemRoleByNameAsync(string name);
        Task<IEnumerable<SystemRole>> GetAllSystemRolesAsync();
        Task<SystemRole> CreateSystemRoleAsync(string name, string description, int level = 0);
        Task<SystemRole?> UpdateSystemRoleAsync(Guid id, string? description, int? level);
        Task<bool> DeleteSystemRoleAsync(Guid id);
        Task<bool> AssignRoleToUserAsync(Guid userId, Guid roleId);
        Task<bool> RemoveRoleFromUserAsync(Guid userId, Guid roleId);
        Task<IEnumerable<SystemRole>> GetUserRolesAsync(Guid userId);
        Task<bool> GrantPermissionToRoleAsync(Guid roleId, Guid permissionId);
        Task<bool> RevokePermissionFromRoleAsync(Guid roleId, Guid permissionId);
        Task<IEnumerable<SystemPermission>> GetRolePermissionsAsync(Guid roleId);
        Task<bool> CheckUserHasRoleAsync(Guid userId, string roleName);
    }

    /// <summary>
    /// 系统用户服务接口
    /// </summary>
    public interface ISystemUserService
    {
        Task<SystemUser?> GetSystemUserByIdAsync(Guid id);
        Task<SystemUser?> GetSystemUserByUsernameAsync(string username);
        Task<SystemUser?> GetSystemUserByEmailAsync(string email);
        Task<IEnumerable<SystemUser>> GetAllSystemUsersAsync(int page = 1, int pageSize = 20);
        Task<SystemUser> CreateSystemUserAsync(string username, string email, string password, string? fullName = null, string? phoneNumber = null);
        Task<SystemUser?> UpdateSystemUserAsync(Guid id, string? email, string? fullName, string? phoneNumber);
        Task<bool> DeleteSystemUserAsync(Guid id);
        Task<bool> ChangeSystemUserPasswordAsync(Guid id, string oldPassword, string newPassword);
        Task<bool> ResetSystemUserPasswordAsync(Guid id, string newPassword);
        Task<bool> LockSystemUserAsync(Guid id, string? reason = null);
        Task<bool> UnlockSystemUserAsync(Guid id);
        Task<bool> ActivateSystemUserAsync(Guid id);
        Task<bool> DeactivateSystemUserAsync(Guid id);
        Task<bool> VerifySystemUserEmailAsync(Guid id);
        Task<bool> VerifySystemUserPhoneAsync(Guid id);
        Task<SystemUser?> UpdateSystemUserProfileAsync(Guid id, string? fullName, string? avatarUrl, string? bio);
        Task<Dictionary<string, object>> GetSystemUserStatisticsAsync();
    }

    /// <summary>
    /// 系统菜单服务接口
    /// </summary>
    public interface ISystemMenuService
    {
        Task<SystemMenu?> GetSystemMenuByIdAsync(Guid id);
        Task<SystemMenu?> GetSystemMenuByCodeAsync(string code);
        Task<IEnumerable<SystemMenu>> GetAllSystemMenusAsync();
        Task<IEnumerable<SystemMenu>> GetSystemMenusByParentIdAsync(Guid? parentId);
        Task<IEnumerable<SystemMenu>> GetUserSystemMenusAsync(Guid userId);
        Task<SystemMenu> CreateSystemMenuAsync(string name, string code, string url, int order = 0, Guid? parentId = null);
        Task<SystemMenu?> UpdateSystemMenuAsync(Guid id, string? name, string? code, string? url, int? order, Guid? parentId);
        Task<bool> DeleteSystemMenuAsync(Guid id);
        Task<bool> GrantMenuToRoleAsync(Guid roleId, Guid menuId);
        Task<bool> RevokeMenuFromRoleAsync(Guid roleId, Guid menuId);
        Task<IEnumerable<SystemMenu>> GetRoleMenusAsync(Guid roleId);
        Task<bool> CheckUserHasMenuAccessAsync(Guid userId, string menuCode);
    }

    /// <summary>
    /// 系统字典服务接口
    /// </summary>
    public interface ISystemDictionaryService
    {
        Task<SystemDictionary?> GetSystemDictionaryByIdAsync(Guid id);
        Task<SystemDictionary?> GetSystemDictionaryByCodeAsync(string code);
        Task<IEnumerable<SystemDictionary>> GetAllSystemDictionariesAsync();
        Task<IEnumerable<SystemDictionary>> GetSystemDictionariesByCategoryAsync(string category);
        Task<SystemDictionary> CreateSystemDictionaryAsync(string code, string name, string value, string? category = null, int order = 0);
        Task<SystemDictionary?> UpdateSystemDictionaryAsync(Guid id, string? name, string? value, string? category, int? order);
        Task<bool> DeleteSystemDictionaryAsync(Guid id);
        Task<bool> DeleteSystemDictionariesByCategoryAsync(string category);
        Task<Dictionary<string, string>> GetSystemDictionaryValuesByCategoryAsync(string category);
        Task<string?> GetSystemDictionaryValueByCodeAsync(string code);
    }

    /// <summary>
    /// 系统区域服务接口
    /// </summary>
    public interface ISystemRegionService
    {
        Task<SystemRegion?> GetSystemRegionByIdAsync(Guid id);
        Task<SystemRegion?> GetSystemRegionByCodeAsync(string code);
        Task<IEnumerable<SystemRegion>> GetAllSystemRegionsAsync();
        Task<IEnumerable<SystemRegion>> GetSystemRegionsByParentIdAsync(Guid? parentId);
        Task<IEnumerable<SystemRegion>> GetSystemRegionsByLevelAsync(int level);
        Task<SystemRegion> CreateSystemRegionAsync(string name, string code, int level, Guid? parentId = null);
        Task<SystemRegion?> UpdateSystemRegionAsync(Guid id, string? name, string? code, int? level, Guid? parentId);
        Task<bool> DeleteSystemRegionAsync(Guid id);
        Task<IEnumerable<SystemRegion>> GetSystemRegionPathAsync(Guid id);
        Task<SystemRegion?> GetSystemRegionByNameAsync(string name);
        Task<IEnumerable<SystemRegion>> SearchSystemRegionsAsync(string keyword);
    }

    /// <summary>
    /// 系统消息模板服务接口
    /// </summary>
    public interface ISystemMessageTemplateService
    {
        Task<SystemMessageTemplate?> GetSystemMessageTemplateByIdAsync(Guid id);
        Task<SystemMessageTemplate?> GetSystemMessageTemplateByCodeAsync(string code);
        Task<IEnumerable<SystemMessageTemplate>> GetAllSystemMessageTemplatesAsync();
        Task<IEnumerable<SystemMessageTemplate>> GetSystemMessageTemplatesByTypeAsync(string type);
        Task<SystemMessageTemplate> CreateSystemMessageTemplateAsync(string code, string name, string type, string title, string content);
        Task<SystemMessageTemplate?> UpdateSystemMessageTemplateAsync(Guid id, string? name, string? type, string? title, string? content);
        Task<bool> DeleteSystemMessageTemplateAsync(Guid id);
        Task<string> RenderSystemMessageTemplateAsync(Guid id, Dictionary<string, object> parameters);
        Task<string> RenderSystemMessageTemplateByCodeAsync(string code, Dictionary<string, object> parameters);
        Task<bool> SendSystemMessageByTemplateAsync(Guid userId, string templateCode, Dictionary<string, object> parameters);
    }

    /// <summary>
    /// 系统统计服务接口
    /// </summary>
    public interface ISystemStatisticsService
    {
        Task<Dictionary<string, object>> GetSystemOverviewStatisticsAsync();
        Task<Dictionary<string, object>> GetUserStatisticsAsync(int days = 30);
        Task<Dictionary<string, object>> GetSystemPerformanceStatisticsAsync(int hours = 24);
        Task<Dictionary<string, object>> GetSystemErrorStatisticsAsync(int days = 7);
        Task<Dictionary<string, object>> GetSystemUsageStatisticsAsync(int days = 30);
        Task<Dictionary<string, object>> GetSystemDatabaseStatisticsAsync();
        Task<Dictionary<string, object>> GetSystemCacheStatisticsAsync();
        Task<Dictionary<string, object>> GetSystemStorageStatisticsAsync();
        Task<Dictionary<string, object>> GetSystemApiStatisticsAsync(int days = 7);
    }
}